<template>
  <div class="nav">
    <div class="nav_info">
      <div><img src="/public/4.jpg" alt="Logo"></div>
    </div>
    <div class="nav_list">
      <span 
        v-for="(item, index) in navlist" 
        :key="index" 
        @click="nav_to(item.name)"
      >
        {{ item.title }}
      </span>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { defineProps, onMounted } from 'vue';
import { useRouter } from 'vue-router';

const Router = useRouter();
let show_global_button = ref(0);

const props = defineProps({
  navlist: {
    type: Array,
    default: () => []
  }
});

const nav_to = (section) => { 
  if (show_global_button.value) {
    Router.push({ name: `${section}` });
  } else {
    const route = Router.resolve({ name: `${section}` });
    window.open(route.href, '_blank');
  }
};

onMounted(() => { 
  show_global_button.value = Number(localStorage.getItem("show_global_button"));
});
</script>

<style scoped>
.nav {
  width: 100%;
  background: linear-gradient(to right, #5cadff, #19be6b);
  height: 50px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  border-radius: 0 0  20px 20px;
}

.nav_info {
  display: flex;
  align-items: center;
  height: 100%;
}

.nav_info > div:first-child {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  margin-right: 10px;
}

.nav_info img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.nav_list {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  height: 100%;
  flex-grow: 1;
  gap: 5px;
}

.nav_list > span {
  user-select: none;
  padding: 5px 15px;
  height: 80%;
  margin: 0 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 16px;
  font-weight: 500;
  border-radius: 4px;
  transition: all 0.3s ease;
  cursor: pointer;
}

.nav_list > span:hover {
  background-color: rgba(255, 255, 255, 0.2);
  color: #fff;
  transform: translateY(-2px);
  border-radius: 50px;
}

/* 响应式调整 */
@media (max-width: 768px) {
  .nav {
    padding: 0 10px;
  }
  .nav_list > span {
    padding: 0 10px;
    font-size: 14px;
  }
}
</style>